﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.StaticFiles;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using W.Device.Domain;
using W.Device.Domain.DTO;
using W.Device.Read.API.Application.Command;

namespace W.Device.Read.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class DeviceController : ControllerBase
    {
        private readonly IMediator mediator;

        public DeviceController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 设备显示
        /// </summary>
        /// <param name="command"></param>
        /// <returns>返回集合</returns>
        [HttpPost]
        public async Task<List<DevicesInfo>> DeviceShow(DeviceShowCommand command)
        {
            return await mediator.Send(command);
        }
        //[HttpPost]
        //public IActionResult Excel()
        //{
        //    byte[] data = null;
        //    string contentType = new FileExtensionContentTypeProvider().Mappings["/.xlsx"];
        //    string fileName = "设备";
        //    IWorkbook book = new XSSFWorkbook();
        //    ISheet sheet = book.CreateSheet();
        //    IRow row = sheet.CreateRow(0);
        //    row.CreateCell(0).SetCellValue("设备编号");
        //    row.CreateCell(1).SetCellValue("设备名称");
        //    row.CreateCell(2).SetCellValue("是否授权");
        //    row.CreateCell(3).SetCellValue("授权标识符");
        //    row.CreateCell(4).SetCellValue("状态");
        //    row.CreateCell(5).SetCellValue("备注");
        //    DeviceShowCommand command = new DeviceShowCommand();
        //    var list = mediator.Send(command);
        //    int index = 0;
        //    foreach (var item  in list)
        //    {

        //        index++;
        //    }
    }
}
